import requests
from django.dispatch import receiver
from .models import TaskActivity
from django.dispatch import Signal

# 自定义信号
task_edited = Signal()
task_deleted = Signal()
task_details = Signal()
task_created = Signal()


# @receiver(task_created)
# def log_user_create(sender, user, instance, **kwargs):
#     TaskActivity.objects.create(user=user, activity_type=f'创建 {instance}')
#

# @receiver(task_edited)
# def log_user_edit(sender, user, instance, **kwargs):
#     TaskActivity.objects.create(user=user, activity_type=f'编辑 {instance}')
#

# @receiver(task_deleted)
# def log_user_delete(sender, user, instance, **kwargs):
#     TaskActivity.objects.create(user=user, activity_type=f'删除 {instance}')


# @receiver(task_details)
# def log_user_details(sender,user, instance, **kwargs):
#     # url = request.headers['Host']
#     # requests.get('http://127.0.0.1:8000/test-due-tasks/')
#     TaskActivity.objects.create(user=user, activity_type=f'查看 {instance}')


